#include "main.h"
//套接字变量
int S,C[3],n=0;
struct login C_login[3]={0};
struct Plink*P=NULL;
int main(int argc, const char *argv[])
{
	//打开文件
	FILE*F=fopen("./login.txt","a+");
	if(F==NULL){perror("打开失败");return -1;}
	//fprintf(F,"账号:%20s  密码:%20s\n","admin","123456");
	//遍历文件至链表
	if((P=my_plink(F))==NULL)return -1;
	//关闭文件
	printf("关闭文件\n");
	fclose(F);
	//搭建服务器端
	//1、创建套接字
	if((S=socket(AF_INET,SOCK_STREAM,0))==-1){perror("创建套接字失败");return -1;}
	//2、绑定本机IP及端口
	struct sockaddr_in addr={0};
	addr.sin_family=AF_INET;
	addr.sin_port=htons(12345);
	addr.sin_addr.s_addr=inet_addr("0.0.0.0");
	//addr.sin_addr.s_addr=inet_addr("192.168.65.128");
	if(bind(S,(struct sockaddr*)&addr,sizeof(addr))==-1){perror("绑定失败");return -1;}
	//3、监听
	listen(S,10);
	//4、多线程等待客户端请求
	pthread_t pth[3];
	for(int i=0;i<3;i++)
	{
		pthread_create(&pth[i],NULL,create_server,&n);//创建线程
		while(n!=i);
	}
	for(int i=0;i<3;i++)
		pthread_join(pth[i],NULL);
	
	close(S);
	return 0;
}
